package com.turnengine.client.local.upkeep;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.turnengine.client.local.unit.interfaces.IUnitIdContainer;
import com.turnengine.client.local.upkeep.bean.IUpkeep;
import com.turnengine.client.local.upkeep.bean.IUpkeepCondition;

public class UpkeepDefinition implements IUpkeepDefinition, IUnitIdContainer {

	private final IUpkeep upkeep;
	private final List<IUpkeepCondition> conditionList = new CopyOnWriteArrayList<IUpkeepCondition>();

	public UpkeepDefinition(IUpkeep upkeep) {
		this.upkeep = upkeep;
	}

	@Override
	public int getUnitId() {
		return getUpkeep().getUpkeepId();
	}

	@Override
	public IUpkeep getUpkeep() {
		return upkeep;
	}

	@Override
	public List<IUpkeepCondition> getConditions() {
		return conditionList;
	}

	@Override
	public void addCondition(IUpkeepCondition condition) {
		if (condition.getUpkeepId() != getUpkeep().getUpkeepId()) {
			throw new IllegalArgumentException("condition=" + condition + ", upkeep=" + getUpkeep());
		}
	}

}
